package cn.edu.scau.cmi.chensicheng.composite.safe;

import java.util.ArrayList;

public class SafeComposite extends SafeComponent {
	public ArrayList<SafeComponent> children = new ArrayList<SafeComponent>();

	public SafeComposite(String name) {
		this.name=name;
	}
	
	public String addChild(SafeComponent child) {
		children.add(child);
		return "成功添加"+child.name+(child instanceof SafeComposite?"组织":"个人");
	}

	public String deleteChild(int index) {
		if(!children.isEmpty()) {
			SafeComponent child=children.get(index);
			children.remove(index);
			return "成功删除"+child.name+(child instanceof SafeComposite?"组织":"个人");
		}
		return "已经没有成员了";
	}

	public ArrayList<SafeComponent> getChildren() {
		return children;
	}

	public String printName() {
		return "我是一个组织, 名叫: " + this.name;
	}
}
